<script setup>
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
import { useAgeStore } from "@/stores/counter.js"
import { storeToRefs } from 'pinia'

const store = useAgeStore();  //store{age,name}


//直接解构会使store中的状态失去响应性
// const {age,name} = store;

// const {age,name} = storeToRefs(store);


// 修改state
//方式1：直接修改，store.age,store.name  age

//方式2:$patch:批量修改状态(建议使用)
// function onPatch() {
//   store.$patch({
//   age:store.age+1,
//   name:'cp',
//   arr:[0,...store.arr,7]
// })
// }

// 方式3:patch中带一个函数(强烈建议)
function onPatch() {
  store.$patch(
    (state) => {
      // state.arr.push(7);
      // state.arr.splice(3,0,4)
      state.age++
    }

  )
}


// subscribe:监听状态的改变

//mutation:追踪修改
store.$subscribe(
  (mutation, state) => {
  }
)




</script>

<template>
  <input type="text" v-model="store.name">
  {{ store.age }} --- {{ store.doubleAge }}  -{{ store.tripleAge }}
  {{ store.name }}
  {{ store.arr }}
  <button @click="onPatch">长大</button>
  <button @click="onSub">订阅</button>
  <br>
  -----------------------------
  <!-- {{ age }}
    {{ name }} -->
  <RouterView />
</template>

<style scoped>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style>
